DataFrame can be created using a single list or a list of lists.
#Import library
import numpy as np
import pandas as pd
#Define data with the help of list
data = [['joe',10],['Andy',18],['Ricky',28]]
#Create DataFrame
df = pd.DataFrame(data,columns = ['Name','Age'])
df
All the ndarrays must be of same length. If index is passed, then the length of the index should equal to the length of the arrays.
If no index is passed, then by default, index will be range(n), where n is the array length.
#Here no index passed
data = {'Name':['Tom', 'Jack', 'Steve', 'Ricky'],'Age':[28,34,29,42]}
df = pd.DataFrame(data)
print (df)
#create an indexed DataFrame using arrays.
data = {'Name':['Tom', 'Jack', 'Steve', 'Ricky'],'Age':[28,34,29,42]}
df = pd.DataFrame(data, index=['rank1','rank2','rank3','rank4'])
print (df)
List of dictonary passed as a input data to create a DataFrame. The dictonary key are by default taken as column name.
data = [{'a': 10, 'b': 20},{'a': 55, 'b': 100, 'c': 200}]
df = pd.DataFrame(data)
print (df)
We will learn how to read diffrent file in Pandas in next chepter